package com.hmall.hmallapi.fallback;

import com.hmall.hmallapi.api.CartService;
import com.hmall.hmallcommon.exception.BizIllegalException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;

/**
 * @author malty
 */
@Slf4j
public class CartServiceFallBack implements FallbackFactory {
    @Override
    public CartService create(Throwable cause) {
        return new CartService() {
            @Override
            public void deleteCartItem(Long id) {
                // 库存扣减业务需要触发事务回滚，查询失败，抛出异常
                throw new BizIllegalException(cause);
            }

            @Override
            public void removeByItemIds(Collection<Long> ids) {
                log.error("远程调用ItemClient#queryItemByIds方法出现异常，参数：{}", ids, cause);
                // 查询购物车允许失败，查询失败，返回空集合
            }
        };
    }
}
